home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d7
/
lanuts.arc
/
HARDWARE.C
< prev
next >
Wrap
Text File
|
1991-10-30
|
6KB
|
195 lines
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <malloc.h>
#include <io.h>
#include <dos.h>
#include "lantasti.h"
/* ********************************************************************
Reports the amount of EMS memory available in kilobytes.
*****************************************************************************/
int ems_avail() {
int handle;
union REGS regs;
/* see if an EMS driver has been loaded */
handle = open("EMMXXXX0",O_RDONLY);
if (handle < 0) return(0);
close(handle);
/* find out how many pages are available */
regs.h.ah = 0x42; /* get unallocated page count */
int86(0x67,®s,®s); /* call the EMS handler */
return(16 * regs.x.bx); /* return the available memory */
}
/* ********************************************************************
Report current DOS version
*****************************************************************************/
int get_dos_version() {
union REGS regs;
int result;
regs.h.ah = 0x30; /* get version # */
intdos(®s,®s);
if (regs.h.al >= 2) result = (100 * regs.h.al) + regs.h.ah;
else result = 100;
return(result);
}
/* ********************************************************************
Report current LANOS version
************************************************************************/
int get_lan_version() {
union REGS regs;
int result;
regs.x.ax = 0xB809;
int86(0x2F,®s,®s);
if (regs.h.ah >= 2) result = (100 * regs.h.ah) + regs.h.al;
else result = 0;
return(result);
}
/* disk_space ****************************************************************
Return free disk space (in K) on current drive.
12/13/88 JEM
******************************************************************************/
int disk_space() {
unsigned long result;
union REGS regs;
regs.h.ah = 0x36; /* get free space interrupt */
regs.h.dl = 0; /* select default drive */
int86(0x21,®s,®s);
result = (unsigned long) regs.x.ax; /* sectors per cluster */
result *= (unsigned long) regs.x.bx; /* number of free clusters */
result *= (unsigned long) regs.x.cx; /* bytes per sector */
return((int) (result / 1024));
}
/* ************************************************************************
Determine the largest contiguous free RAM area
*****************************************************************************/
#define KBYTE 1024
int ram_free() {
char huge *memory;
long count,left,right;
left = 1 ; right = 600;
do {
count = (left + right) / 2;
memory = halloc(count,KBYTE);
if (memory == NULL) right = count - 1;
else {
hfree(memory);
left = count + 1;
}
} while (left < right);
count += 0; /* add this program's space back in */
return((int) count);
}
/* ********************************************************************
Returns TRUE if an MS Compatible mouse driver is running
*****************************************************************************/
mouse_present() {
union REGS regs;
regs.x.ax = 0; /* attempt to initialize mouse */
int86(0x33,®s,®s);
if (regs.x.ax) return(TRUE);
else return(FALSE);
}
/* find_6845 ********************************************************************
Returns TRUE if a CRT controller lives at the given address
*****************************************************************************/
int find_6845(addr)
int addr;
{
unsigned char oldval;
int result,i;
outp(addr,0xF); /* select cursor low scan line register */
addr += 1;
oldval = inp(addr); /* save current value */
outp(addr,0x66); /* try to write trash */
for (i = 0;i < 100; i++) ; /* wait for chip to respond */
result = (0x66 == inp(addr)); /* see if we wrote the value correctly */
outp(addr,oldval); /* restore original value */
return(result);
}
/* video_type ********************************************************************
Returns video type - 0 = mono, 1 = herc, 2 = cga, 3 = ega, 4 = mcga/vga
*****************************************************************************/
int video_type() {
union REGS regs;
unsigned char oldval;
int i;
/* check for VGA card */
regs.x.ax = 0x1200;
regs.x.bx = 0x0036;
int86(0x10,®s,®s);
if (regs.h.al == 0x12) return(4);
/* check for an EGA card */
regs.x.ax = 0x1200;
regs.x.bx = 0x0010;
regs.x.cx = 0xF;
int86(0x10,®s,®s);
if (regs.h.bl != 0x10) return(3);
/* is it a CGA card? */
if(find_6845(0x3D4)) return(2);
/* is it a monochrome or hercules card? */
if (!find_6845(0x3B4)) {
puts("Error: Unknown video system");
exit(-1);
}
/* see if it's a herc */
oldval = inp(0x3BA) & 0x80; /* status port */
/* wait around to see if the status register changes */
for (i = 0;i < 5000; i++)
/* if it changes, it's a hercules card of some type */
if (oldval != (inp(0x3BA) & 0x80)) return(1);
/* if it doesn't, we've got a plain old mono monitor */
return(0);
}
/* ********************************************************************
Report the amount of extended memory available, in Kbytes
*****************************************************************************/
int ext_avail() {
union REGS regs;
if (cpu_type() < 286) return(0);
regs.x.ax = 0x8800; /* get ext size fn */
int86(0x15,®s,®s);
if (regs.x.ax == 0x8800) return(0); /* function not supported */
return(regs.x.ax); /* return ext. memory size */
}